<?php
/**
* @desc 定制表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class CustomizeForm extends BaseForm
{
	public $destination;
	public $personNum;
	public $startTime;
	public $contant;
	private $_user;
	private $_identity;
	//表单规则
	public function rules()
	{
		return array(
			array('destination, personNum, startTime, contant', 'required', 'message'=>'提交的表单数据不完整'),
			array('personNum', 'type', 'type'=>'integer', 'message'=>'请输入合法的人数'),
			array('startTime', 'authenticate', 'message'=>'出行时间必须大于当前时间'),
			array('contant', 'match', 'pattern'=>'/((1(([35][0-9])|(47)|[8][01236789]))\d{8})/','message'=>'联系方式请输入合法的手机号'),
		);
	}
	//密码验证
	public function authenticate($attribute,$params)
	{
		$startTime = strtotime($this->startTime);
		$currentTime = time();
		if($startTime <= $currentTime){
			$this->addError('startTime',$params['message']);
		}
	}
	//用户登录
	public function book()
	{
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = array(
			'username' => $userInfo['username'],
			'destination' => $this->destination,
			'person_num' => $this->personNum,
			'start_time' => $this->startTime,
			'contant' => $this->contant
			);
		$model = new Customize;
		$result = $model->insertCustomize($data);
		if(!empty($result)){
			$this->addError('bookError',"定制失败");
		}
		return $result;
	}
}
